{extend name="public:base" /}
{block name="head"}
<link href="__PUBLIC__/view_res/mobile/css/wshop_company_center.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/lib/weui.min.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/view_res/mobile/css/login.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/css/jquery-weui.min.css" type="text/css" rel="Stylesheet" />
<script src="__PUBLIC__/jquery-weui/dist/js/jquery-weui.min.js"></script>
<link href="__PUBLIC__/view_res/mobile/css/uc.css" type="text/css" rel="Stylesheet" />
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

{/block}
{block name="header"}
{include file="public/top-nav" /}
{/block}

{block name="content"}
<style>
    body{
        background:none;
    }
</style>
<header class="Thead">申请提货</header>

{:token()}

<div style="margin:0 10px;">
    <div class="gs-text">
        <select name="exchange_id" style="width: 100%; height: 28px"  id ="exchange_id">
            <option value ="">--   交易所   --</option>
            {volist name="exchange" id="ex" empty="$exchange"}
            <option value="{$ex.id}" {if condition="input('param.exchange_id') eq $ex.id"} selected {/if} >{$ex.name}</option>
            {/volist}
        </select>
    </div>
</div>
<div style="margin:0 10px;">
    <div class="gs-text">
        <select name="variety_id" style="width: 100%; height: 28px"  id="variety_id">
            <option value="">--   交易品种   --</option>
        </select>
    </div>
</div>
<!--
<div style="margin:0 10px;">
    <div class="gs-text">
        <select name="time_day" style="width: 100%; height: 28px"  id="time_day">
            <option value="">--   选择周期   --</option>
            <option value="1">短期（活动）</option>
            <option value="2">长期</option>
        </select>
    </div>
</div>-->
<div style="margin:0 10px;">
    <div class="gs-text">
        <input type="number" step="0.01" name="num" value="" autocomplete="off"  tabindex="2" placeholder="请输入计划提货金额(长期5000-50000,短期5000-10000),允许10%的浮动" />
    </div>
</div>
<input type="hidden" name="username" value="{$username}">

<!--<p style="margin-left: 20px"><span style="color: #ff0905;font-size: 20px">*</span>&nbsp;&nbsp;申请时间为每日9:30之前，以及15:00以后</p>-->

<input class="button green" id="reg-btn" type="submit" value="确认提交" style="background: #e54245;">

<div id="ulist">
    {volist name="list" id="p"}
    <section class="ulist clearfix">
        <div>
            <span class="ulist_p">{$p.sub_date}</span>
			<span class="ulist_data" style="padding:0 8px;display: block;">
				名称：申请提货<br>
				交易所：{:get_trade_name($p.exchange_id)}<br>
				交易品种：{:get_variety_name($p.variety_id)}<br>
				计划提货金额：{$p.num}<br>
                申请周期：{if condition="$p.time_day eq 1"}短期{else}长期{/if}<br>
                {if condition="$p.abn_state eq 0 and $p.state eq 3"}
                实际提货金额：{:floatval($p.total)}<br>
                {/if}
                状态：
                {if condition="$p.abn_state eq 0"}
                    {if condition="$p.state eq 0"}
                    申请审核
                    {elseif condition="$p.state eq 1"}
                    待提交提货凭证
                    {elseif condition="$p.state eq 2"}
                    已提交提货凭证，正在审核中
                    {elseif condition="$p.state eq 3"}
                    审核通过
                    {else}
                    正在审核中
                    {/if}
                {elseif condition="$p.abn_state eq 1"}
                申请审核不通过
                {elseif condition="$p.abn_state eq 2"}
                凭证审核不通过
                {/if}
                <br>
                {if condition="$p.abn_state neq 1"}
                    {if condition="$p.state eq 1 or $p.state eq 2 or $p.state eq 4"}
                    <a href="{:url('contract/programme_img',['id'=>$p.id])}" class="btn btn-default" role="button">上传提货凭证</a>
                    {/if}
                {/if}
			</span>
        </div>
    </section>
    {/volist}
</div>
<div style="text-align: right;padding:2% 3%;">
    数据总数:{$list->total()}条
    {$page}
</div>
<script type="text/javascript">
    $('#exchange_id').change(function(){
        //alert("abc");
        var iframe_array = <?php echo  json_encode($variety);   ?>;
        var checkValue=jQuery("#exchange_id").val();
        //alert(checkValue);
        $("#variety_id").empty();
        for (var i = 0; i <iframe_array.length ; i++)
        {
            if(iframe_array[i]['exchange_id']==checkValue)
            {
                var opt = "<option value='"+iframe_array[i]['id']+"'>"+iframe_array[i]['name']+"</option>";
                jQuery("#variety_id").append(opt);
            }
        }

    })
</script>
<script>
    $('#reg-btn').click(function(){

        var exchange_id = $('#exchange_id option:selected').val();
        var variety_id  = $('#variety_id option:selected').val();
        var time_day  = $('#time_day option:selected').val();
        var num      = $('input[name="num"]').val();
        var token      = $('input[name="__token__"]').val();
        var username      = $('input[name="username"]').val();

        if(exchange_id == '' || exchange_id == null || variety_id == '' || variety_id == null){
            $.toast('请选择交易所及交易品种', "forbidden");
            return;
        }
       

        if(num == '' || num < 0 || num == null){
            $.toast('请输入正确的提货的金额', "forbidden");
            return;
        }

        $.ajax({
            url : '{:url("Contract/programme")}',
            data : {exchange_id:exchange_id,variety_id:variety_id,num:num,token:token,username:username,time_day:time_day},
            type : 'post',
            success:function(d){
                if(d.error){
                    $.toast(d.error, "forbidden");
                }else if(d.success){
                    $.toast(d.success);
                    setTimeout(function (){
                        window.location.href = "/mobile/Contract/programme";
                    },1000);
                }
            }
        });

    });
</script>
{/block}